﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ApplLogic.ApplClasses;
using ConnectionObjects;
using TCPClient.RequestsToServerHandlers;
using TCPClient.UI.LogicForUserControls;

namespace TCPClient.UI
{
    public partial class PersonalDetailsForm : Form
    {

        private ApplWorker m_LoggedInWorkerRef = null;
        public PersonalDetailsForm(ApplWorker loggedInWorker)
        {
            m_LoggedInWorkerRef = loggedInWorker;
            InitializeComponent();
            setDefaultValuesInTheTextBoxes();
        }
         
        private void setDefaultValuesInTheTextBoxes()
        {
            textBoxFirstName.Text = m_LoggedInWorkerRef.PersonalDetails.FirstName;
            textBoxLastName.Text = m_LoggedInWorkerRef.PersonalDetails.LastName;
            textBoxId.Text = m_LoggedInWorkerRef.PersonalDetails.Id;
            textBoxMailFirst.Text = m_LoggedInWorkerRef.PersonalDetails.EmailAdress.Split('@')[0];
            textBoxMailSecond.Text = m_LoggedInWorkerRef.PersonalDetails.EmailAdress.Split('@')[1];
            textBoxPassword.Text = m_LoggedInWorkerRef.PersonalDetails.Password;
            textBoxUserName.Text = m_LoggedInWorkerRef.PersonalDetails.UserName;
            textBoxDateYear.Text = m_LoggedInWorkerRef.PersonalDetails.BirthDate.Year.ToString();
            textBoxDateMonth.Text = m_LoggedInWorkerRef.PersonalDetails.BirthDate.Month.ToString();
            textBoxDateDay.Text = m_LoggedInWorkerRef.PersonalDetails.BirthDate.Day.ToString();
            textBoxSOFYear.Text = m_LoggedInWorkerRef.StartOfWork.Year.ToString();
            textBoxSOFMounth.Text = m_LoggedInWorkerRef.StartOfWork.Month.ToString();
            textBoxSOFDay.Text = m_LoggedInWorkerRef.StartOfWork.Day.ToString();
            textBoxMaxShiftNumber.Text = m_LoggedInWorkerRef.MaxShiftsThatCanGive.ToString();

        }

        private void buttonSaveDetails_Click(object sender, EventArgs e)
        {
            m_LoggedInWorkerRef.PersonalDetails.FirstName = textBoxFirstName.Text;
            m_LoggedInWorkerRef.PersonalDetails.LastName = textBoxLastName.Text;
            m_LoggedInWorkerRef.PersonalDetails.EmailAdress = string.Format("{0}@{1}", textBoxMailFirst.Text, textBoxMailSecond.Text);
            m_LoggedInWorkerRef.PersonalDetails.Password = textBoxPassword.Text;
            m_LoggedInWorkerRef.PersonalDetails.UserName = textBoxUserName.Text;
            m_LoggedInWorkerRef.PersonalDetails.BirthDate = new DateTime(int.Parse(textBoxDateYear.Text),
                                                                              int.Parse(textBoxDateMonth.Text),
                                                                              int.Parse(textBoxDateDay.Text));
            m_LoggedInWorkerRef.MaxShiftsThatCanGive = int.Parse(textBoxMaxShiftNumber.Text);
            ScMainUserControlLogic.Instance.UpdateWorker();
            this.Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
